namespace SharpObjects.XpathToObjects_Test
{
    public class UserInfo
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string[] Roles { get; set; }

        public override bool Equals(object obj)
        {
            if(obj == null)
            {
                return false;
            }

            UserInfo userInfo = (UserInfo) obj;

            bool nameMatch = this.FirstName == userInfo.FirstName && this.LastName == userInfo.LastName;

            if(!nameMatch)
            {
                return false;
            }

            if((this.Roles == null && userInfo.Roles != null)
                || (this.Roles != null && userInfo.Roles == null))
            {
                return false;
            }

            if(this.Roles == null && userInfo.Roles == null)
            {
                return true;
            }

            if(this.Roles.Length == 0 && userInfo.Roles.Length == 0)
            {
                return true;
            }

            for(int k = 0; k < this.Roles.Length; k++)
            {
                if(this.Roles[k] != userInfo.Roles[k])
                {
                    return false;
                }
            }

            return true;
        }
    }
}